CC  = gcc
CPP = g++
LD  = ld

INCLUDES = -I../../common/lib/sglib_v2 -I../../common/lib/serverbase -I../../common/3rd/curl/include -I../protobuf-2.5.0/src -I../../common/lib/sglib_v2/http -I../../common/3rd/httpparser -I../../common/3rd/jsoncpp -I../../common/3rd/jsoncpp/include
LIBS = $(OS_LIB) ../../common/lib/serverbase/libserverbase.a ../../common/lib/sglib_v2/libsgnet2.a ../../common/3rd/curl/libcurl.a ../protobuf-2.5.0/src/libs/libprotobuf.a ../../common/3rd/httpparser/libhttpparser.a ../../common/3rd/jsoncpp/libjsoncpp.a -ldl -lpthread -lrt -lnsl -lgcc_s

OUT_DIR = .
OUT_FILE = sgrobot

VER = Debug
DEBUG  = -g -Wall -D_REENTRANT -DDEBUG -D_USE_CURL_
RELEASE = -g -Wall -D_REENTRANT -D_USE_CURL_ -O2 
CPPFLAGS = $(INCLUDES) 
ifneq ($(strip $(MAKECMDGOALS)), release)
CPPFLAGS := $(CPPFLAGS) $(DEBUG)
LD_FLAGS = -pthread -rdynamic
else
CPPFLAGS := $(CPPFLAGS) $(RELEASE)
LD_FLAGS = -pthread -rdynamic
VER = Release 
endif
CPP_FLAGS := $(CPPFLAGS) -Wall

CUR_FILES = $(wildcard *.cpp)
CUR_OBJS = $(CUR_FILES:.cpp=.o)

.PHONY : all release clean

all release:$(OUT_FILE)

$(OUT_FILE):$(CUR_OBJS)
	$(CPP) -o $(OUT_DIR)/$@ $^ $(LD_FLAGS) $(LIBS)

$(CUR_OBJS):%.o:%.cpp
	$(CPP) $(CPP_FLAGS) -c $<

display:
	echo $(ALL_FILES)
	echo $(OBJS)

clean:
	rm -f $(CUR_OBJS)
	cd $(OUT_DIR) && rm -f $(OUT_FILE) core.*

